package assists
{
	import assists.Base64;
	import assists.log.Log;
	import assists.serialization.json.JSON;
	
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	public class LonLatChange
	{
		private static var _loader:URLLoader;
		private static var jsonObj:Object;
		
		public static function googleToBaidu(obj:*):void
		{
			if(obj){
				var list:Array = [];
				
				
				jsonObj = new Object;
				_loader = new URLLoader;
				var urlRe:URLRequest = new URLRequest("http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x=" + obj.location[1] + "&y=" + obj.location[0]);
				_loader.addEventListener(Event.COMPLETE,getResult);
				_loader.load(urlRe);
				
				function getResult(e:Event):void
				{
					_loader.removeEventListener(Event.COMPLETE,getResult);
					
					if(String(e.target.data).indexOf("'error':2") == -1){
						
						jsonObj = assists.serialization.json.JSON.decode(e.target.data);
						list = [Base64.decode(jsonObj.y),Base64.decode(jsonObj.x)];
						obj.location = list;
					}
				}
				
			}
		}
		
	}
}